﻿Imports System.Runtime.InteropServices
Imports System.Security.Permissions

Public Class frmMain
    Private Elearning As String = "http://elearning.vimaru.edu.vn"

    <DllImport("urlmon.dll", CharSet:=CharSet.Ansi)> _
    Private Shared Function UrlMkSetSessionOption(ByVal dwOption As Integer, ByVal pBuffer As String, ByVal dwBufferLength As Integer, ByVal dwReserved As Integer) As Integer
    End Function

    Public Sub ChangeUserAgent(ByVal Agent As String)
        UrlMkSetSessionOption(&H10000001, Agent, Agent.Length, 0)
    End Sub

    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ChangeUserAgent("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.8pre) Gecko/20100116 SEB")
        cbbAddress.Text = Elearning
        btnGo_Click(Nothing, Nothing)
    End Sub

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        wbbMain.Navigate(cbbAddress.Text)
    End Sub

    Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
        wbbMain.GoBack()
    End Sub

    Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForward.Click
        wbbMain.GoForward()
    End Sub

    Private Sub btnHome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHome.Click
        wbbMain.Navigate(Elearning)
    End Sub

    Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        wbbMain.Refresh()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        wbbMain.Stop()
    End Sub

    Private Sub wbbMain_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles wbbMain.ProgressChanged
        prbLoading.Visible = Not (e.CurrentProgress = e.MaximumProgress)
        prbLoading.Value = CInt(e.CurrentProgress / e.MaximumProgress * 100)
        tsslStatus.Text = wbbMain.StatusText
    End Sub

    Private Sub wbbMain_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wbbMain.DocumentCompleted
        Text = My.Application.Info.Title & " - " & wbbMain.DocumentTitle
        cbbAddress.Text = wbbMain.Url.ToString()
        btnBack.Enabled = wbbMain.CanGoBack
        btnForward.Enabled = wbbMain.CanGoForward
        btnCancel.Enabled = False
    End Sub

    Private Sub tsslInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsslInfo.Click
        System.Diagnostics.Process.Start("http://fb.me/luong.xuan.manh")
    End Sub

    Private Sub wbbMain_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles wbbMain.Navigating
        btnCancel.Enabled = True
    End Sub

    Private Sub cbbAddress_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cbbAddress.KeyUp
        If e.KeyCode = Keys.Enter Then
            btnGo_Click(Nothing, Nothing)
        End If
    End Sub
End Class
